package com.tdt.alarm;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;

import com.tdt.alarm.controller.MainActivity;

public class SplashScreen extends Activity {

	protected boolean _active = true;
	protected int splashTime = 3000; // time to display the splash screen in ms
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash_screen);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.splash_screen, menu);

//        new Handler().postDelayed(new Runnable() {
//                public void run() {
//                        startActivity(new Intent(SplashScreen.this, MainActivity.class));
//                        finish();
//                }
//        }, splashTime);
		
		Thread splashTread = new Thread() {
	        @Override
	        public void run() {
	            try {
	                int waited = 0;
	                while (_active && (waited < splashTime)) {
	                    sleep(100);
	                    if (_active) {
	                        waited += 100;
	                    }
	                }
	            } catch (Exception e) {

	            } finally {

	                startActivity(new Intent(SplashScreen.this,
	                        MainActivity.class));
	                finish();
	            }
	        };
	             };
	    splashTread.start();
		return true;
	}
}
